package noobteam.deartrainer.service;

import noobteam.deartrainer.mapper.CourseInfoMapper;

import java.time.LocalDate;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author 高
 */
@Service
public class CourseInfoService {
    @Resource
    private CourseInfoMapper courseInfoMapper;

    /**
     * 监控注册功能：向 课程表 插入信息
     */
    public boolean trainerAddCourse(Map<String,String> map){
        boolean flag=false;
        //选择要添加监控的代码
        //ctrl+alt+t 打开 surround with窗口 选择 try catch
        try {
            boolean r=courseInfoMapper.createCourse(map);
            if(r){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            //记录日志，写到文件中进行保存
        }
        return flag;
    }

    public List<Map<String,Object>> getAllCourseCodeInfo(){
        List<Map<String,Object>> list = null;
        try {
            list = courseInfoMapper.findAllCourseCodeInfo();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String,Object>> getAllCourseInfo(){
        List<Map<String,Object>> list = null;
        try {
            list = courseInfoMapper.getALLCourseList();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public Map<String, Object> getCourseInfoById(int courseId) {
        Map<String,Object> map = null;
        try {
            map = courseInfoMapper.getCourseInfoById(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    public List<Map<String, Object>> getCourseListByTrainerPhone(int trainerPhone) {
        List<Map<String, Object>> map = null;
        try {
            map = courseInfoMapper.getCourseInfoByTrainerPhone(trainerPhone);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    public List<Map<String, Object>> getCourseListByDate() {
        List<Map<String,Object>> list = null;
        LocalDate date = LocalDate.now();
        try {
            list = courseInfoMapper.getCourseListOrderByDate(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getCourseListOrderByNum() {
        List<Map<String, Object>> list = null;
        try {
            list = courseInfoMapper.getCourseListOrderByNum();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getCourseListOrderByType(String courseType) {
        List<Map<String, Object>> list= null;
        try {
            list = courseInfoMapper.getCourseOfType(courseType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getCourseListOrderByName() {
        List<Map<String, Object>> list= null;
        try {
            list = courseInfoMapper.getCourseListOrderByName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public boolean updateCourseMsg(Map<String, String> course) {
        boolean isSucceed = false;
        try {
            isSucceed = courseInfoMapper.updateCourseMsg(course);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public double getCoursePrice(int courseId) {
        double price = 0;
        try {
            price = courseInfoMapper.getCoursePrice(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return price;
    }

    public boolean addStudent(int courseId) {
        boolean isSucceed = false;
        try {
            isSucceed = courseInfoMapper.addStudent(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public boolean deleteStudent(int courseId) {
        boolean isSucceed = false;
        try {
            isSucceed = courseInfoMapper.deleteStudent(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public List<Map<String, Object>> getTrainerCourseOrderByStudentNum(int trainerId) {
        List<Map<String, Object>> list = null;
        try {
            list = courseInfoMapper.getTrainerCourseOrderByStudentNum(trainerId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getTrainerCourseOrderByStartTime(int trainerId) {
        List<Map<String, Object>> list = null;
        try {
            list = courseInfoMapper.getTrainerCourseOrderByStartTime(trainerId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public boolean updateCoursePhoto(Map<String, String> map) {
        boolean flag=false;
        try {
            boolean r = courseInfoMapper.updateCoursePhoto(map);
            if(r){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    public boolean deleteCourseById(int courseId) {
        boolean flag=false;
        try {
            boolean r = courseInfoMapper.deleteCourseById(courseId);
            if(r){
                flag=true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

}

